<cfcomponent output="false">

	<cffunction name="read" output="false" access="public" returntype="Comment">
		<cfargument name="id" required="true">
		<cfset var qRead="">
		<cfset var obj="">

		<cfquery username="#request.username#" password="#request.password#" name="qRead" datasource="nwharvest">
			select 	ID, USER_ID, FOODDRIVE_ID, COMMENT_TEXT, VISIBLE
			from dbo.COMMENTS
			where ID = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.id#" />
		</cfquery>

		<cfscript>
			obj = createObject("component", "Comment").init();
			obj.ID = qRead.ID;
			obj.USER_ID = qRead.USER_ID;
			obj.FOODDRIVE_ID = qRead.FOODDRIVE_ID;
			obj.COMMENT_TEXT = qRead.COMMENT_TEXT;
			obj.VISIBLE = qRead.VISIBLE;
			return obj;
		</cfscript>
	</cffunction>



	<cffunction name="create" output="false" access="public">
		<cfargument name="bean" required="true" type="Comment">
		<cfset var qCreate="">

		<cfset var local1=arguments.bean.USER_ID>
		<cfset var local2=arguments.bean.FOODDRIVE_ID>
		<cfset var local3=arguments.bean.COMMENT_TEXT>
		<cfset var local4=arguments.bean.VISIBLE>

		<cftransaction isolation="read_committed">
			<cfquery username="#request.username#" password="#request.password#" name="qCreate" datasource="nwharvest">
				insert into dbo.COMMENTS(USER_ID, FOODDRIVE_ID, COMMENT_TEXT, VISIBLE)
				values (
					<cfqueryparam value="#local1#" cfsqltype="CF_SQL_INTEGER" null="#iif((local1 eq ""), de("yes"), de("no"))#" />,
					<cfqueryparam value="#local2#" cfsqltype="CF_SQL_INTEGER" null="#iif((local2 eq ""), de("yes"), de("no"))#" />,
					<cfqueryparam value="#local3#" cfsqltype="CF_SQL_LONGVARCHAR" />,
					<cfqueryparam value="#local4#" cfsqltype="CF_SQL_BIT" null="#iif((local4 eq ""), de("yes"), de("no"))#" />
				)
				select @@Identity as pkID
			</cfquery>
		</cftransaction>

		<cfscript>
			arguments.bean.ID = qCreate.pkID;
		</cfscript>
		<cfreturn arguments.bean />
	</cffunction>



	<cffunction name="update" output="false" access="public">
		<cfargument name="bean" required="true" type="Comment">
		<cfset var qUpdate="">

		<cfquery username="#request.username#" password="#request.password#" name="qUpdate" datasource="nwharvest" result="status">
			update dbo.COMMENTS
			set USER_ID = <cfqueryparam value="#arguments.bean.USER_ID#" cfsqltype="CF_SQL_INTEGER" null="#iif((arguments.bean.USER_ID eq ""), de("yes"), de("no"))#" />,
				FOODDRIVE_ID = <cfqueryparam value="#arguments.bean.FOODDRIVE_ID#" cfsqltype="CF_SQL_INTEGER" null="#iif((arguments.bean.FOODDRIVE_ID eq ""), de("yes"), de("no"))#" />,
				COMMENT_TEXT = <cfqueryparam value="#arguments.bean.COMMENT_TEXT#" cfsqltype="CF_SQL_LONGVARCHAR" />,
				VISIBLE = <cfqueryparam value="#arguments.bean.VISIBLE#" cfsqltype="CF_SQL_BIT" null="#iif((arguments.bean.VISIBLE eq ""), de("yes"), de("no"))#" />
			where ID = <cfqueryparam value="#arguments.bean.ID#" cfsqltype="CF_SQL_INTEGER">
		</cfquery>
		<cfreturn arguments.bean />
	</cffunction>



	<cffunction name="delete" output="false" access="public" returntype="void">
		<cfargument name="bean" required="true" type="Comment">
		<cfset var qDelete="">

		<cfquery username="#request.username#" password="#request.password#" name="qDelete" datasource="nwharvest" result="status">
			delete
			from dbo.COMMENTS
			where ID = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.bean.ID#" />
		</cfquery>

	</cffunction>


</cfcomponent>